﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;


namespace DTcms.Web.m
{
    /// <summary>
    /// member_order 的摘要说明
    /// </summary>
    public class member_order : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            BLL.member_order bll = new BLL.member_order();
            BLL.users userbll = new BLL.users();
            BLL.company combll = new BLL.company();
            DataSet ds = bll.GetList(6, " payment_status=1 ", "payment_time desc");
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"order_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"user_id\":" + dr["user_id"]);
                    strTxt.Append(",\"user_name\":\"" + userbll.GetUserName(int.Parse( dr["user_id"].ToString()))+"\"");
                   
                    Model.company com = combll.GetModel(combll.GetCompanyID(int.Parse(dr["user_id"].ToString())));
                    if (com != null)
                    {
                        strTxt.Append(",\"company_id\":\"" + com.id + "\"");
                        strTxt.Append(",\"company_name\":\"" + com.title + "\"");
                    }
                    else {
                        strTxt.Append(",\"company_id\":\"\"");
                        strTxt.Append(",\"company_name\":\"\"");
                    }
                    strTxt.Append(",\"user_id\":" + dr["user_id"]);
                    strTxt.Append(",\"user_name\":\"" + userbll.GetUserName(int.Parse(dr["user_id"].ToString())) + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }

                }
                strTxt.Append("]");
            }
            else { strTxt.Append("\"status\":2,\"order_list\":[]"); }
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}